package com.hxzy.tms;

import java.util.List;

public class Page<T> {
	// 总页数
	private final int totalPageCount;

	// 页面大小，即每页显示的记录数
	private final int pageSize;

	// 总记录数
	private final int totalCount;

	// 当前页码
	private final int currPageNo;

	private List<T> list;
	
	private final int offset;

	public Page(int totalCount, int pageSize, int currPageNo) {
		if (pageSize < 0) {
			throw new IllegalArgumentException("页面大小，即每页显示的记录数不能小于 0");
		}
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.totalPageCount = ((this.totalCount % this.pageSize) == 0) ? (this.totalCount / this.pageSize)
				: ((this.totalCount / this.pageSize) + 1);
		this.currPageNo = Math.min(currPageNo, this.totalPageCount);
		this.offset = ((this.currPageNo - 1) * this.pageSize); // 0, 5, 10, ...
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public int getCurrPageNo() {
		return currPageNo;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public int getOffset() {
		return offset;
	}

}
